Skip to content

Preserve original indexes in right-reduction callbacks - #380

Merged
dgilland merged 2 commits into
dgilland:developfrom
jipeng6036-del:fix/preserve-right-reduction-indexes
Oct 27, 2026
Merged

dgilland merged 2 commits into
dgilland:developfrom
jipeng6036-del:fix/preserve-right-reduction-indexes

Conversation

@jipeng6036-del

Copy link
Copy Markdown
Contributor

reduce_right reverses sequence values and then numbers them from zero, so three-argument callbacks receive the wrong original indexes. For example:

reduce_right([10, 20, 30], lambda total, value, index: total + value * (index + 1), 0)
# before: 100; expected: 140

Reverse the original key/value pairs instead. This also fixes reductions_right and reductions(..., from_right=True), while preserving mapping keys and input order. Six regressions cover lists, tuples, iterators, and reductions with and without an initial accumulator.

Validation against baseline ef6a6427e488e29e827e0e0819f2630ad3ff4cdc and candidate 5674ec55d429ade516688fe696688d588b246aa9:

  • New regressions: 6 fail on the baseline, all 6 pass with the fix.
  • Official Linux tox environments py310, py311, py312, py313, py314 all pass: package build, strict Sphinx docs, Ruff, mypy, generated chaining types, and 2,886 unit/doctests with 100% coverage each.
  • Windows Python 3.13.1 configured suite: baseline 2,880 / candidate 2,886 passed, both 100% coverage; Ruff and mypy pass.
  • A CSV consumer checks original row positions and weighted totals through each tox-installed package, plus a same-environment baseline/candidate control on Windows.

Commands, versions, source manifests, logs, and consumer proof. GitHub CI will run after submission; these are local results.

AI assistance: implemented and validated with OpenAI Codex.

@coveralls

Copy link
Copy Markdown

Coverage Status

coverage: 100.0%. remained the same — jipeng6036-del:fix/preserve-right-reduction-indexes into dgilland:develop

@dgilland
dgilland merged commit ea48375 into dgilland:develop Oct 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants